package com.thinkfit.jy.adapter;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.thinkfit.jy.R;
import com.thinkfit.jy.utils.ImageLoadUtils;
import com.thinkfit.jy.utils.LogUtils;
import com.thinkfit.jy.utils.SystemUtils;
import com.thinkfit.jy.view.MyCircleProgress;
import com.tonyodev.fetch2.Download;
import com.tonyodev.fetch2.Status;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;


class Utils {

    private Utils() {

    }

    protected static String[] dataUnits = {"B", "KB", "MB", "GB", "TB"};

    protected static String readableBytes(long bytes) {
        double size = bytes > 0 ? bytes : 0;
        int index = 0;
        while (size / 1024 >= 1) {
            size /= 1024;
            ++index;
        }

        return String.format("%.2f %s", size, dataUnits[index]);
    }

    @NonNull
    public static String getMimeType(@NonNull final Context context, @NonNull final Uri uri) {
        final ContentResolver cR = context.getContentResolver();
        final MimeTypeMap mime = MimeTypeMap.getSingleton();
        String type = mime.getExtensionFromMimeType(cR.getType(uri));
        if (type == null) {
            type = "*/*";
        }
        return type;
    }

    public static void deleteFileAndContents(@NonNull final File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                final File[] contents = file.listFiles();
                if (contents != null) {
                    for (final File content : contents) {
                        deleteFileAndContents(content);
                    }
                }
            }
            file.delete();
        }
    }

    @NonNull
    public static String getETAString(@NonNull final Context context, final long etaInMilliSeconds) {
        if (etaInMilliSeconds < 0) {
            return "";
        }
        int seconds = (int) (etaInMilliSeconds / 1000);
        long hours = seconds / 3600;
        seconds -= hours * 3600;
        long minutes = seconds / 60;
        seconds -= minutes * 60;
        if (hours > 0) {
            return String.format("%dh %dm %ds left", hours, minutes, seconds);
        } else if (minutes > 0) {
            return String.format("%dm %ds left", minutes, seconds);
        } else {
            return String.format("%ds left", seconds);
        }
    }

    @NonNull
    public static String getDownloadSpeedString(@NonNull final Context context, final long downloadedBytesPerSecond) {
        if (downloadedBytesPerSecond < 0) {
            return "";
        }
        double kb = (double) downloadedBytesPerSecond / (double) 1000;
        double mb = kb / (double) 1000;
        final DecimalFormat decimalFormat = new DecimalFormat(".##");
        if (mb >= 1) {
            return String.format("%s MB/s", decimalFormat.format(mb));
        } else if (kb >= 1) {
            return String.format("%s KB/s", decimalFormat.format(kb));
        } else {
            return String.format("%d B/s", downloadedBytesPerSecond);
        }
    }

    @NonNull
    public static File createFile(String filePath) {
        final File file = new File(filePath);
        if (!file.exists()) {
            final File parent = file.getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            }
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return file;
    }

    public static int getProgress(long downloaded, long total) {
        if (total < 1) {
            return -1;
        } else if (downloaded < 1) {
            return 0;
        } else if (downloaded >= total) {
            return 100;
        } else {
            return (int) (((double) downloaded / (double) total) * 100);
        }
    }

}

public class DownloadAdapter extends RecyclerView.Adapter<DownloadAdapter.ViewHolder> {

    public interface ActionListener {
        void onPauseDownload(int id);

        void onResumeDownload(int id);

        void onRemoveDownload(int id);

        void onRetryDownload(int id);
    }

    @NonNull
    private final List<DownloadData> downloads = new ArrayList<>();
    @NonNull
    private final ActionListener actionListener;

    private boolean isDownVisibility = true;//下载按钮是否显示  默认显示
    private boolean isStartAndPausedVisibility = false;//开始和暂停是否显示  默认不显示
    private boolean isRemovedVisibility = false;//删除任务是否显示  默认不显示
    private boolean isProgressVisibility = false;//进度条是否显示  默认不显示
    private boolean isInstallProgressVisibility = false;//安装加载是否显示  默认不显示
    private boolean isDownloadSucceed = false;//下载是否完成 默认未完成
    private boolean isRemoved = false;//是否已经取消下载 默认不是
    private String state="";//状态内容

    public DownloadAdapter(@NonNull final ActionListener actionListener) {
        this.actionListener = actionListener;
    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_download, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
//        holder.actionButton.setOnClickListener(null);
//        holder.actionButton.setEnabled(true);
//        holder.removeButton.setEnabled(true);

        final DownloadData downloadData = downloads.get(position);
        String url = "";
        String local = "";
        Status status = Status.NONE;
        int progress = 0;
        if (downloadData.download != null) {
            url = downloadData.download.getUrl();
            local = downloadData.download.getFile();
            status = downloadData.download.getStatus();
            progress = downloadData.download.getProgress();
            if (progress == -1) { // Download progress is undermined at the moment.
                progress = 0;
            }
//            holder.fileSizeTextView.setVisibility(View.VISIBLE);
//            holder.fileSizeTextView.setText(Utils.readableBytes(downloadData.download.getTotal()));
        }
        LogUtils.getInstance().l(LogUtils.HINT,"dddddddddddddddddddddd  progress :"+progress);

        final Uri uri = Uri.parse(url);
        final Context context = holder.itemView.getContext();

//        holder.indexTextView.setText(String.format("[%d].%s", position + 1, local.substring(local.lastIndexOf("/")+1)));
//        String boardType ="";
//        if(!TextUtils.isEmpty(downloadData.boardType)){
//            if(downloadData.boardType.equals("Droidlogic")){
//                boardType = "(单屏版)";
//            }else if(downloadData.boardType.equals("rockchip")){
//                boardType = "(双屏版)";
//            }
//        }
        int version = SystemUtils.getVersion(context, downloadData.packageName);
        LogUtils.getInstance().l(LogUtils.HINT,"aaaaaaaaaaaaaaaaaaaaaaaaa  packageName : "+downloadData.packageName +"  version :"+version);

//        System.out.println("ddddddddddddddddddddddddddddd  boardType : "+boardType);
        if(version>0){
//            holder.indexTextView.setText(downloadData.appName+"("+SystemUtils.getVersionName(context, downloadData.packageName)+")"
//                    +boardType);
            holder.ivDelete.setVisibility(View.VISIBLE);
            holder.shaderView.setVisibility(View.GONE);
            holder.downButton.setVisibility(View.VISIBLE);
            holder.ivIcon.setEnabled(true);
//            holder.actionButton.setVisibility(View.GONE);
//            holder.removeButton.setVisibility(View.GONE);
            downloads.get(position).isDownVisibility = false;
            downloads.get(position).isProgressVisibility = false;
            downloads.get(position).isInstallProgressVisibility = false;
            downloads.get(position).isState = false;
//            downloads.get(position).isDelete = false;
        }else {
//            holder.indexTextView.setText(downloadData.appName+boardType);
            downloads.get(position).isDownVisibility = true;
            holder.ivDelete.setVisibility(View.GONE);
            holder.shaderView.setVisibility(View.VISIBLE);
            holder.downButton.setVisibility(View.GONE);
            holder.ivIcon.setEnabled(false);
//            holder.actionButton.setVisibility(View.GONE);
//            holder.removeButton.setVisibility(View.GONE);
            downloads.get(position).isDelete = false;
        }

        if(!downloads.get(position).isState){
            holder.tvName.setText(downloadData.name);
        }else {
            holder.tvName.setText(state);
        }

        if(downloads.get(position).isDelete){
            holder.ivDelete.setVisibility(View.GONE);
            holder.shaderView.setVisibility(View.VISIBLE);
        }

        ImageLoadUtils.getInstance(context).setImageUtlRadius(holder.ivIcon,downloadData.icon,0,22);
        holder.ivIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.click(v,downloadData,position);
            }
        });
        holder.ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                clickLong.clickLong(v,downloadData,position);
                return true;
            }
        });
//        if(version != 0 && version >= downloadData.versionCode){
////            holder.downButton.setImageResource(R.mipmap.img_refresh_un);
//            holder.downButton.setEnabled(false);
//            state = "当前已是最新版本";
//        }else {
//            if(version == 0){
//                holder.downButton.setEnabled(true);
////                holder.downButton.setImageResource(R.mipmap.img_down);
//                state = "";
//            }else {
//                holder.downButton.setEnabled(true);
////                holder.downButton.setImageResource(R.mipmap.img_refresh);
//                state = "";
//            }
//        }


//        holder.statusTextView.setText(getStatusString(status));
//        holder.createdTextView.setText(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss(S)").format(new Date(downloadData.download.getCreated())));


//        holder.tvNewVersion.setText("最新版本:"+downloadData.versionName);
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa   progress : "+progress);
        holder.progressBar.SetCurrent(progress);
//        holder.progressTextView.setText(String.format("%d%%", progress));

//        if (downloadData.eta == -1) {
//            holder.timeRemainingTextView.setText("");
//        } else {
//            holder.timeRemainingTextView.setText(Utils.getETAString(context, downloadData.eta));
//        }

//        if (downloadData.downloadedBytesPerSecond == 0) {
//            holder.downloadedBytesPerSecondTextView.setText("");
//        } else {
//            holder.downloadedBytesPerSecondTextView.setText(Utils.getDownloadSpeedString(context, downloadData.downloadedBytesPerSecond));
//        }

        if(downloads.get(position).isDownVisibility){
            holder.downButton.setVisibility(View.VISIBLE);
//            holder.fileSizeTextView.setVisibility(View.GONE);
        }else {
            holder.downButton.setVisibility(View.GONE);
//            holder.fileSizeTextView.setVisibility(View.VISIBLE);
        }

//        if(downloads.get(position).isStartAndPausedVisibility){
//            holder.actionButton.setVisibility(View.VISIBLE);
//        }else {
//            holder.actionButton.setVisibility(View.GONE);
//        }
//
//        if(downloads.get(position).isRemovedVisibility){
//            holder.removeButton.setVisibility(View.VISIBLE);
//        }else {
//            holder.removeButton.setVisibility(View.GONE);
//        }


//        holder.tvState.setText(state);

        if(downloads.get(position).isDownloadSucceed){
//            holder.removeButton.setVisibility(View.GONE);
//            holder.removeButton.setImageResource(R.mipmap.img_del_un);
//            holder.removeButton.setEnabled(false);
//            holder.actionButton.setImageResource(R.mipmap.img_play_un);
//            holder.actionButton.setEnabled(false);
            holder.progressBar.setVisibility(View.GONE);
        }

        if(downloads.get(position).isProgressVisibility){
            holder.progressBar.setVisibility(View.VISIBLE);
            holder.downButton.setVisibility(View.GONE);
        }else {
            holder.progressBar.setVisibility(View.GONE);
        }
        if(downloads.get(position).isInstallProgressVisibility){
            holder.pbProgress.setVisibility(View.VISIBLE);
            holder.downButton.setVisibility(View.GONE);
        }else {
            holder.pbProgress.setVisibility(View.GONE);
        }

//        holder.removeButton.setOnClickListener(view -> {
//            holder.actionButton.setEnabled(false);
//            if(downloadData.download != null){
//                actionListener.onRemoveDownload(downloadData.download.getId());
//            }
//            isStartAndPausedVisibility = false;
//            isRemovedVisibility = false;
//            isProgressVisibility = false;
//            isDownVisibility = true;
//            state = "";
//            File file = new File(downloadData.download.getFile());
//            if(file.exists()){
//                file.delete();
//            }
//            isRemoved = true;
//            downloads.set(position,downloadData);
//            notifyItemChanged(position);
//        });
        holder.ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.click(v,downloadData,position);
            }
        });

        switch (status) {
            case COMPLETED: {//下载完成
//                holder.actionButton.setVisibility(View.GONE);
//                holder.actionButton.setImageResource(R.mipmap.img_play_un);
//                holder.actionButton.setOnClickListener(view -> {
//                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//                        Toast.makeText(context, "Downloaded Path:" + downloadData.download.getFile(), Toast.LENGTH_LONG).show();
//                        return;
//                    }
//                    final File file = new File(downloadData.download.getFile());
//                    final Uri uri1 = Uri.fromFile(file);
//                    final Intent share = new Intent(Intent.ACTION_VIEW);
//                    share.setDataAndType(uri1, Utils.getMimeType(context, uri1));
//                    context.startActivity(share);
//                });
                break;
            }
            case FAILED: {//下载失败
//                holder.actionButton.setImageResource(R.drawable.img_play);//RETRY重试
//                holder.actionButton.setOnClickListener(view -> {
//                    holder.actionButton.setEnabled(false);
                    actionListener.onRetryDownload(downloadData.download.getId());
//                });
                break;
            }
            case PAUSED: {
//                holder.actionButton.setImageResource(R.drawable.img_play);
//                holder.actionButton.setOnClickListener(view -> {
////                    holder.actionButton.setEnabled(false);
//                    actionListener.onResumeDownload(downloadData.download.getId());
//                });
                break;
            }
            case DOWNLOADING://下载中
            case QUEUED: {//下载中
//                isStartAndPausedVisibility = true;
//                isRemovedVisibility = true;
//                isProgressVisibility = true;
//                isDownVisibility = false;
                if(isRemoved){
                    state = "";
                }else {
                    state = context.getString(R.string.app_application_downloading_installing);
                }
//                holder.actionButton.setImageResource(R.drawable.img_pause);
//                holder.actionButton.setOnClickListener(view -> {
////                    holder.actionButton.setEnabled(false);
//                    actionListener.onPauseDownload(downloadData.download.getId());
//                });
                break;
            }
            case ADDED: {//创建下载任务
//                holder.actionButton.setImageResource(R.mipmap.img_play);
//                holder.actionButton.setOnClickListener(view -> {
//                    holder.actionButton.setEnabled(false);
//                    actionListener.onResumeDownload(downloadData.download.getId());
//                });
                break;
            }
            case REMOVED: {
                if(downloadData.download != null){
                    File file = new File(downloadData.download.getFile());
                    if(file.exists()){
                        file.delete();
                    }
                    System.out.println("ddddddddddddddddddddddddddd   删除下载任务");
                    state = "";
                }
                break;
            }
            default: {
                break;
            }
        }


        holder.downButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.click(v,downloadData,position);
                isRemoved = false;
            }
        });

//        holder.tvState.setText(state);
        //Set delete action
//        holder.itemView.setOnLongClickListener(v -> {
//            final Uri uri12 = Uri.parse(downloadData.download.getUrl());
//            new AlertDialog.Builder(context)
//                    .setMessage(String.format("Are you sure you want to delete %s?", uri12.getLastPathSegment()))
//                    .setPositiveButton("Delete", (dialog, which) -> actionListener.onRemoveDownload(downloadData.download.getId()))
//                    .setNegativeButton("Cancel", null)
//                    .show();
//
//            return true;
//        });

    }

    public void setDownVisibility(boolean b,int position){
        downloads.get(position).isDownVisibility = b;
        notifyItemChanged(position);
    }

    public void setStartAndPausedVisibility(boolean b,int position){
        downloads.get(position).isStartAndPausedVisibility = b;
        notifyItemChanged(position);
    }

    public void setRemovedVisibility(boolean b,int position){
        downloads.get(position).isRemovedVisibility = b;
        notifyItemChanged(position);
    }
    public void setProgressVisibility(boolean b,int position){
        downloads.get(position).isProgressVisibility = b;
        notifyItemChanged(position);
    }
    public void setInstallProgressVisibility(boolean b,int position){
        downloads.get(position).isInstallProgressVisibility = b;
        notifyItemChanged(position);
    }

    public void downloadSucceed(boolean b,int position){
        downloads.get(position).isDownloadSucceed = b;
        notifyItemChanged(position);
    }

    public void setStateText(String s,int position){
        state = s;
        notifyItemChanged(position);
    }


    public List<DownloadData> getData(){
        return downloads;
    }

    Click click;
    ClickLong clickLong;

    public void setOnClick(Click click){
        this.click = click;
    }

    public interface Click{
        void click(View v,DownloadData downloadData,int position);
    }

    public void setOnLongClick(ClickLong clickLong){
        this.clickLong = clickLong;
    }

    public interface ClickLong{
        void clickLong(View v,DownloadData downloadData,int position);
    }

    public void addDownload(DownloadData downloadData){
        System.out.println("dddddddddddddddddddd   downloads.size :"+downloads.size());
//        if(downloadData != null){
//            if(downloadData.download != null){
//                addDownload(downloadData.download);
//            }else {
                downloads.add(downloadData);
//            }
//        }

    }

    public void setNewData(List<DownloadData> list){
        for (DownloadData downloadData : list){
            downloads.add(downloadData);
        }
    }

    public void addDownload(@NonNull final Download download) {
//        boolean found = false;
        DownloadData data = null;
        int dataPosition = -1;
        for (int i = 0; i < downloads.size(); i++) {
            final DownloadData downloadData = downloads.get(i);
            if (downloadData.downloadId == download.getId()) {
                System.out.println("dddddddddddddddddddddddddd   position1  "+i);
                data = downloadData;
                dataPosition = i;
//                found = true;
                break;
            }
        }
        System.out.println("dddddddddddddddddddddddddd   position2  "+dataPosition);
        data.download = download;
        notifyItemChanged(dataPosition);
//        if (!found) {
//            final DownloadData downloadData = new DownloadData();
//            downloadData.downloadId = download.getId();
//            downloadData.download = download;
//            downloads.add(downloadData);
//            notifyItemInserted(downloads.size() - 1);
//        } else {
//
//        }
    }

    public int getPosition(Download download){
        int dataPosition = 0;
        for (int i = 0; i < downloads.size(); i++) {
            final DownloadData downloadData = downloads.get(i);
            if (downloadData.downloadId == download.getId()) {
                dataPosition = i;
                break;
            }
        }
        return dataPosition;
    }
    public int getPosition(String packageName){
        int dataPosition = 0;
        for (int i = 0; i < downloads.size(); i++) {
            final DownloadData downloadData = downloads.get(i);
            if (downloadData.packageName == packageName) {
                dataPosition = i;
                break;
            }
        }
        return dataPosition;
    }

    public int getPackagePosition(String packageName){
        int dataPosition = 0;
        for (int i = 0; i < downloads.size(); i++) {
            final DownloadData downloadData = downloads.get(i);
            if (packageName.equals(downloadData.packageName)) {
                dataPosition = i;
                break;
            }
        }
        return dataPosition;
    }

    public int getUrlPosition(String url){
        int dataPosition = 0;
        for (int i = 0; i < downloads.size(); i++) {
            final DownloadData downloadData = downloads.get(i);
            if (downloadData.url.equals(url)) {
                dataPosition = i;
                break;
            }
        }
        return dataPosition;
    }




    public void removeDownload(int i){
        downloads.remove(i);
        notifyItemRemoved(i);
    }
    public void removeAllDownload(){
        downloads.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return downloads.size();
    }

    public void update(@NonNull final Download download, long eta, long downloadedBytesPerSecond) {
        for (int position = 0; position < downloads.size(); position++) {
            final DownloadData downloadData = downloads.get(position);
            if(downloadData.downloadId == download.getId()){
//                downloadData.id = download.getId();
                System.out.println("dddddddddddddddddddddddddd   downloadData.id: "+downloadData.downloadId);
                System.out.println("dddddddddddddddddddddddddd   download.getId: "+download.getId());
                System.out.println("dddddddddddddddddddddddddd   download.getStatus: "+download.getStatus());
//            if (downloadData.id == download.getId()) {
                switch (download.getStatus()) {
                    case REMOVED:
                    case DELETED: {
//                        downloads.remove(position);
                        downloadData.isProgressVisibility = false;
                        downloadData.isStartAndPausedVisibility = false;
                        downloadData.isDownVisibility = true;
                        downloadData.isRemovedVisibility = false;
//                        isStartAndPausedVisibility = false;
//                        isRemovedVisibility = false;
//                        isProgressVisibility = false;
//                        isDownVisibility = true;
                        state = "";
                        File file = new File(download.getFile());
                        if(file.exists()){
                            file.delete();
                        }
                        System.out.println("dddddddddddddddddddddddddd   state: "+state);
                        notifyItemChanged(position);
                        break;
                    }
                    default: {
                        downloadData.isProgressVisibility = true;
                        downloadData.isStartAndPausedVisibility = true;
                        downloadData.isDownVisibility = false;
                        downloadData.isRemovedVisibility = true;
//                        isProgressVisibility = true;
//                        isStartAndPausedVisibility = true;
//                        isRemovedVisibility = true;
//                        isDownVisibility = false;

                        downloadData.download = download;
                        System.out.println("dddddddddddddddddddddddddd   download.Progress: "+position);
                        downloadData.eta = eta;
                        downloadData.downloadedBytesPerSecond = downloadedBytesPerSecond;
                        notifyItemChanged(position);
                    }
                }
                return;
//            }
            }

        }
    }

    private String getStatusString(Status status) {
        switch (status) {
            case COMPLETED:
                return "Done";
            case DOWNLOADING:
                return "Downloading";
            case FAILED:
                return "Error";
            case PAUSED:
                return "Paused";
            case QUEUED:
                return "Waiting in Queue";
            case REMOVED:
                return "Removed";
            case NONE:
                return "Not Queued";
            default:
                return "Unknown";
        }
    }

    public void installSuccess(String packageName){
        List<DownloadData> data = getData();
        for (DownloadData bean : data) {
            if (bean.packageName.equals(packageName) ||
                    ("package:" + bean.packageName).equals(packageName)) {
//                bean.setInstallStatus(2);
                int position = getPosition(packageName);
                notifyItemChanged(position);
                break;
            }
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

//        public final TextView indexTextView;
//        public final TextView remoteTextView;
//        final TextView statusTextView;
        public final MyCircleProgress progressBar;
        public final ProgressBar pbProgress;
//        public final TextView progressTextView;
        public final ImageView downButton;
//        public final ImageView actionButton;
//        public final ImageView removeButton;
        public final ImageView ivDelete;
        public final ImageView ivIcon;
//        final TextView tvState;
        final TextView tvName;
        final View shaderView;
//        final TextView tvNewVersion;
//        final TextView createdTextView;
//        final TextView fileSizeTextView;
//        final TextView timeRemainingTextView;
//        final TextView downloadedBytesPerSecondTextView;

        ViewHolder(View itemView) {
            super(itemView);
//            tvState = itemView.findViewById(R.id.tv_state);
            tvName = itemView.findViewById(R.id.tvName);
            shaderView = itemView.findViewById(R.id.shaderView);
            ivIcon = itemView.findViewById(R.id.ivIcon);
//            indexTextView = itemView.findViewById(R.id.indexTextView);
//            remoteTextView = itemView.findViewById(R.id.remoteTextView);
//            statusTextView = itemView.findViewById(R.id.status_TextView);
//            tvNewVersion = itemView.findViewById(R.id.new_version);
            progressBar = itemView.findViewById(R.id.progressBar);
            pbProgress = itemView.findViewById(R.id.pb_progress);
            downButton = itemView.findViewById(R.id.downButton);
            ivDelete = itemView.findViewById(R.id.ivUninstall);
//            actionButton = itemView.findViewById(R.id.actionButton);
//            removeButton = itemView.findViewById(R.id.removeButton);
//            progressTextView = itemView.findViewById(R.id.progress_TextView);
//            createdTextView = itemView.findViewById(R.id.createdTextView);
//            fileSizeTextView = itemView.findViewById(R.id.fileSizeTextView);
//            timeRemainingTextView = itemView.findViewById(R.id.remaining_TextView);
//            downloadedBytesPerSecondTextView = itemView.findViewById(R.id.downloadSpeedTextView);
        }

    }

    public static class DownloadData {
        public String id;
        public int downloadId;
        @Nullable
        public Download download;
        long eta = -1;
        long downloadedBytesPerSecond = 0;
        public String name;//修改内容
        public String appName;//应用类型（相机，游戏，小黄鹿）
        public String url;
        public String originName;
        public String versionName;
        public int versionCode;
        public int type;
        public String md5;
        public String packageName;
        public String downloadPath;
        public String downloadFileName;
        public String boardType;
        public String icon;
        public boolean isDownloadSucceed = false;
        public boolean isInstallProgressVisibility = false;
        public boolean isProgressVisibility = false;
        public boolean isStartAndPausedVisibility = false;
        public boolean isDownVisibility = true;
        public boolean isRemovedVisibility = false;
        public boolean isState = false;
        public boolean isDelete = false;
        public boolean isDown = false;


        @Override
        public int hashCode() {
            return downloadId;
        }

        @Override
        public String toString() {
            return "DownloadData{" +
                    "id=" + id +
                    "downloadId=" + downloadId +
                    ", download=" + download +
                    ", eta=" + eta +
                    ", downloadedBytesPerSecond=" + downloadedBytesPerSecond +
                    ", name='" + name + '\'' +
                    ", appName='" + appName + '\'' +
                    ", url='" + url + '\'' +
                    ", version='" + versionName + '\'' +
                    ", versionCode=" + versionCode +
                    ", originName=" + originName +
                    ", type=" + type +
                    ", md5='" + md5 + '\'' +
                    ", packageName='" + packageName + '\'' +
                    ", downloadPath='" + downloadPath + '\'' +
                    ", downloadFileName='" + downloadFileName + '\'' +
                    ", boardType='" + boardType + '\'' +
                    ", icon='" + icon + '\'' +
                    '}';
        }

        @Override
        public boolean equals(Object obj) {
            return obj == this || obj instanceof DownloadData && ((DownloadData) obj).downloadId == downloadId;
        }
    }

}
